package cn.com.lms.business.examRewrite.service;

import cn.com.lms.business.examRewrite.persistence.entity.PaperExtraReWrite;
import cn.com.lms.business.examRewrite.persistence.repository.PaperExtraReWriteDao;
import com.bnzj.core.persistence.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PaperExtraReWriteService extends BaseService<PaperExtraReWriteDao, PaperExtraReWrite,Long> {

    /**
     * 保存paperExtraReWrite
     * @param id
     * @param paperTotalScore
     * @param paperTotalCount
     */
    @Transactional(rollbackFor = Exception.class)
    public void savePaperExtra(Long id, Integer paperTotalScore, Integer paperTotalCount) {
        // 判断 id 是否已存在 ，存在修改，不存在保存
        PaperExtraReWrite paperExtraReWrite = repository.getPaperExtra(id);
        if (paperExtraReWrite==null){
            // 不存在 保存
            PaperExtraReWrite paperExtraReWrite1 = new PaperExtraReWrite();
            paperExtraReWrite1.setPaperId(id);
            paperExtraReWrite1.setPaperScore(paperTotalScore);
            paperExtraReWrite1.setSubjectCount(paperTotalCount);
            save(paperExtraReWrite1);
        }else {
            // 存在 修改
            repository.updataPaperExtraReWrite(id,paperTotalScore,paperTotalCount);
        }
    }

    /**
     * 通过PaperId获取数据
     * @param id
     * @return
     */
    public PaperExtraReWrite getPaperExtraReWriteByPaperId(Long id) {
        return repository.getPaperExtraReWriteByPaperId(id);
    }


    /**
     * 通过PaperId删除
     * @param ids
     */
    public void deletePaperExtraReWriteByPaperId(List<Long> ids) {
            repository.deletePaperExtraReWriteByPaperId(ids);


    }
}
